"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global globalRootUrl, ConferenceRoomsAPI, Extensions, globalTranslate, UserMessage */

/**
 * Module handling interactions with the conference room table.
 * @module conferenceTable
 */
var conferenceTable = {
  $conferencesTable: $('#conference-rooms-table'),

  /**
   * Initializes module functionality.
   * Specifically, it adds a double click event handler to the rows of the conference table.
   */
  initialize: function initialize() {
    // Attach double-click event handler to each cell in the conference room table
    // The handler redirects to a URL specific to the conference room for editing
    $('.record-row td').on('dblclick', function (e) {
      var id = $(e.target).closest('tr').attr('id');
      window.location = "".concat(globalRootUrl, "conference-rooms/modify/").concat(id);
    }); // Set up delete functionality on delete button click.

    $('body').on('click', 'a.delete', function (e) {
      e.preventDefault();
      $(e.target).addClass('disabled'); // Get the conference room  ID from the closest table row.

      var rowId = $(e.target).closest('tr').attr('id'); // Remove any previous AJAX messages.

      $('.message.ajax').remove(); // Call the PbxApi method to delete the conference room record.

      ConferenceRoomsAPI.deleteRecord(rowId, conferenceTable.cbAfterDeleteRecord);
    });
  },

  /**
   * Callback function executed after deleting a record.
   * @param {Object} response - The response object from the API.
   */
  cbAfterDeleteRecord: function cbAfterDeleteRecord(response) {
    if (response.result === true) {
      // Remove the deleted record's table row.
      conferenceTable.$conferencesTable.find("tr[id=".concat(response.data.id, "]")).remove(); // Call the callback function for data change.

      Extensions.cbOnDataChanged();
    } else {
      // Show an error message if deletion was not successful.
      UserMessage.showError(response.messages.error, globalTranslate.cr_ImpossibleToDeleteConferenceRoom);
    }

    $('a.delete').removeClass('disabled');
  }
};
/**
 *  Initialize conference rooms table on document ready
 */

$(document).ready(function () {
  conferenceTable.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9Db25mZXJlbmNlUm9vbXMvY29uZmVyZW5jZS1yb29tcy1pbmRleC5qcyJdLCJuYW1lcyI6WyJjb25mZXJlbmNlVGFibGUiLCIkY29uZmVyZW5jZXNUYWJsZSIsIiQiLCJpbml0aWFsaXplIiwib24iLCJlIiwiaWQiLCJ0YXJnZXQiLCJjbG9zZXN0IiwiYXR0ciIsIndpbmRvdyIsImxvY2F0aW9uIiwiZ2xvYmFsUm9vdFVybCIsInByZXZlbnREZWZhdWx0IiwiYWRkQ2xhc3MiLCJyb3dJZCIsInJlbW92ZSIsIkNvbmZlcmVuY2VSb29tc0FQSSIsImRlbGV0ZVJlY29yZCIsImNiQWZ0ZXJEZWxldGVSZWNvcmQiLCJyZXNwb25zZSIsInJlc3VsdCIsImZpbmQiLCJkYXRhIiwiRXh0ZW5zaW9ucyIsImNiT25EYXRhQ2hhbmdlZCIsIlVzZXJNZXNzYWdlIiwic2hvd0Vycm9yIiwibWVzc2FnZXMiLCJlcnJvciIsImdsb2JhbFRyYW5zbGF0ZSIsImNyX0ltcG9zc2libGVUb0RlbGV0ZUNvbmZlcmVuY2VSb29tIiwicmVtb3ZlQ2xhc3MiLCJkb2N1bWVudCIsInJlYWR5Il0sIm1hcHBpbmdzIjoiOztBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQSxJQUFNQSxlQUFlLEdBQUc7QUFFcEJDLEVBQUFBLGlCQUFpQixFQUFFQ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